<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="<%=basePath %>js/jquery.js"></script>
<title>考试系统</title>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 12; }
.STYLE10 {color: #000000; font-size: 12px; }
.STYLE19 {
	color: #344b50;
	font-size: 12px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
-->
</style>
<script type="text/javascript">
		
		$(function(){
			  $("#showteacher").click(function (){
				if($("#teacher").css("display") == 'none'){
					$("#teacher").css("display","block");
				}
				else
					$("#teacher").css("display","none");
			  }) 
		})

		function info(id){
			 window.location.href="<%=request.getContextPath() %>/Clazz/ClazzAction!StuInfo.action?id="+id;
		}
		var nameflag;
		function checkname(){
			$("#addteainfo").text("");
			var username = $.trim($("#username").val());
			var id = <s:property value="clazz.id" />
			if(!username.length == 0){
				$.get("<%=request.getContextPath()%>/Clazz/ClazzAction!checkname.action?username="+username+"&id="+id,null,checkCallback)
			}
		}
		
		function checkCallback(data){
			var arr = new Array();
			arr = data.split("%");
			if(arr[0]==1){
				nameflag = true;
			}
			else{
				
				$("#addteainfo").text("该学号已存在");				
				nameflag = false;
			}
		}
		 
		function check(){
			var username = $.trim($("#username").val());
			var password = $.trim($("#password").val());
			var stuname = $.trim($("#stuname").val());
			if(username.length == 0 || password.length == 0 || stuname.length == 0 ){
				$("#addteainfo").text("请将信息填写完整");
				flag =  false;
			}
			else
				flag =  true;	
		}
		
		function tosubmit(){
			check();
			if(flag && nameflag)
				$("#addStudent").submit();
		}
		
		var flag;
		function del(id,status){
			if(confirm("是否确定删除")){
				todel(id,status);
			}
		}
		
		function todel(id,status){
			flag = status;
			$.get("<%=request.getContextPath()%>/Clazz/ClazzAction!delStudent.action?id="+id,null,delcallback)
		}
		
		function delcallback(data){
			if(data != null){
				alert(data);
				alert(flag);
				$("#"+flag).hide();
			}
			else
				alert("删除失败！");
		}
		
		
</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE1"> 学生基本信息列表</span></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr><td>班号:<s:property value="clazz.classnum" />&nbsp;班级名称:<s:property value="clazz.classname" /></td></tr>
  <tr>
    <td><table width="400" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
      <tr>
        <td width="10%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">编号</span></div></td>
        <td width="30%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">学号</span></div></td>
        <td width="35%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">姓名</span></div></td>
        <td width="25%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">操作</span></div></td>
      </tr>
      
      <s:iterator value="stuList" id="student" status = "status">
	  <tr id="<s:property value='#status.index'/>">
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"> <s:property value="#status.index+1" /> </div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#student.username" /></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#student.stuname" /></div></td>
		<td height="20" bgcolor="#FFFFFF"><div align="center"><span class="STYLE21">

			 <input type="button" value="详细" onclick="info(<s:property value="#student.id" />)" />
			 <input type="button" value="删除" onclick="del(<s:property value="#student.id" />,<s:property value="#status.index"/>)" />
			 </span></div></td>
	  </tr>
	  </s:iterator>
    </table></td>
  </tr>
</table>

<span id="showteacher" style="cursor:hand" >点击该处可添加班级用户</span>
<div id="teacher" style="display:none;">

<form id="addStudent" action="./Clazz/ClazzAction!addStudent.action" method="post">
	<table width="20%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
		
		<tr>
			 <td width="40%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">班级</span></div></td>
			 <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center">  <input type="text" readonly="readonly" style="display:none" name="student.clazz.id" value="<s:property value="clazz.id" />"/>
			 <s:property value="clazz.classnum" />
			 </div></td>
		</tr>
		
		<tr>
			 <td width="40%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">学号(即为用户名)</span></div></td>
			 <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><input type="text"  name="student.username" id="username" onchange="checkname()" /></div></td>
		</tr>
		
		<tr>
			 <td width="40%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">密码</span></div></td>
			 <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><input type="text" name="student.password" id="password"  /> </div></td>
		</tr>
		<tr>
			 <td width="40%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">真实姓名</span></div></td>
			 <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><input type="text" name="student.stuname" id = "stuname"  /> </div></td>
		</tr>	
		
		<tr>
			  <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"> <input type="button" value="提交" onclick="tosubmit()"></div></td>
			  <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"> <input type="reset" value="重置">  </div></td>
		</tr>
		<tr><span id = "addteainfo" style="color: red"></span></tr>
	</table>
	</form>
</div>
   
   		

</body>
</html>
